<?php
/*
 * 商家入住
 */

namespace app\adminbackstage\controller;
use app\BaseController;
use think\facade\Request;
use app\adminbackstage\model\MerchantContact;


class MerchantContactController extends BaseController{

    //商家入住列表
    public function merchantContactList(){
        $a_uid = Request::param('a_uid');
        $page = Request::param('page');
        $num = Request::param('num');
        $state = Request::param('state');
//        $express_name = Request::param('express_name');
        $name = Request::param('name');
        $phone = Request::param('phone');
//        $username = Request::param('username');
//        $o_pro_num = Request::param('o_pro_num');
//        $p_num = Request::param('p_num');

        $where = [];
        $where[] = ['enable','=','1'];
        if(!empty($name)){
            $where[] = ['name','like','%'.$name.'%'];
        }
        
        if(!empty($phone)){
            $where[] = ['phone','='.$phone];
        }
        
        if(!empty($state)){
            $where[] = ['state','='.$state];
        }

        $list = MerchantContact::merchantContactList($where,$page,$num);
        if(!empty($list)){
            $list = $list->toArray();
            foreach ($list as $key => $value) {
                $list[$key]["addtime"] = date( "Y-m-d H:i:s",$value["addtime"]);
                
                    /*if(strpos($value['img'],"img.alicdn.com") !== false){
                        $storeList[$key]["img"] =  $value['img'];
                    }
                    elseif(strpos($value['img'],"http") !== false){
                        $storeList[$key]["img"] =  $value['img'];
                    }
                    else{
                        
                        $storeList[$key]["img"] =  Config::get('app.swimming_url').$value['img'];
                    }*/
            }
        }
        $count = MerchantContact::merchantContactCount($where);
        return json(['code' => 1, 'msg' => lang(''), 'data' => $list, 'count' => $count]);
    }
    
    //评价添加
//    public function evaluationAdd(){
//        //$store = new Store();
//        $a_uid = Request::param('a_uid');
//        $enable = Request::param('enable');
//        $express_name = Request::param('express_name');
//        $unit_weight_min = Request::param('unit_weight_min');
//        $unit_weight_max = Request::param('unit_weight_max');
//        $unit = Request::param('unit');
//        $price = Request::param('price');
//        $w_id = Request::param('w_id');
//        
//        if(empty($enable)){
//            $enable = 1;
//        }
//        if($enable == -1){
//            $enable  = 0;
//        }
//        $time = time();
//        $data = [
//            'express_name' => $express_name,
//            'unit_weight_min' => $unit_weight_min,
//            'unit_weight_max' => $unit_weight_max,
//            'unit' => $unit,
//            'price' => $price,
//            'w_id' => $w_id,
//            'enable' => $enable,
//            'addtime' => $time,
//        ];
//
//        Evaluation::evaluationAdd($data);
//        return json(['code' => 1, 'msg' => lang(''), 'data' => '', 'count' => '']);
//    }
    
    //商家入住详情
    public function merchantContactInfo(){
        $a_uid = Request::param('a_uid');

        $id = Request::param('id');
       
  
        $where = [];
 
        $where[] = ['id','=',$id];

        $info = MerchantContact::merchantContactInfo($where);
     


        
        if(!empty($info)){
            $info = $info->toArray();

            $info["addtime"] = date( "Y-m-d H:i:s",$info["addtime"]);

            /*if(strpos($storeList['img'],"img.alicdn.com") !== false){
                $storeList["img"] =  $storeList['img'];
            }
            elseif(strpos($storeList['img'],"http") !== false){
                $storeList["img"] =  $storeList['img'];
            }
            else{

                $storeList["img"] =  Config::get('app.swimming_url').$storeList['img'];
            }*/
       
        }

        return json(['code' => 1, 'msg' => lang(''), 'data' => $info, 'count' => '' ]);
    }
    
    //商家入住修改
    public function merchantContactEdit(){

        $a_uid = Request::param('a_uid');
        $id = Request::param('id');
        $enable = Request::param('enable');
        $state = Request::param('state');
//        $unit_weight_min = Request::param('unit_weight_min');
//        $unit_weight_max = Request::param('unit_weight_max');
//        $unit = Request::param('unit');
//        $price = Request::param('price');
        $remarks = Request::param('remarks');
        
        $update = [];
        if(!empty($state)){
            $update['state'] = $state;
        }
        
//        if(!empty($unit_weight_min)){
//            $update['unit_weight_min'] = $unit_weight_min;
//        }
//        
//        if(!empty($unit_weight_max)){
//            $update['unit_weight_max'] = $unit_weight_max;
//        }
//        
        if(!empty($remarks)){
            $update['remarks'] = $remarks;
        }
//        
//        if(!empty($price)){
//            $update['price'] = $price;
//        }
//        
//        if(!empty($w_id)){
//            $update['w_id'] = $w_id;
//        }
//        
        if($enable==-1){
            $update['enable'] = 0;
        }else{
            $update['enable'] = 1;
        }


        MerchantContact::merchantContactEdit($id,$update);
        return json(['code' => 1, 'msg' => lang(''), 'data' => '', 'count' => '']);
    }

}
